package com.zzz.demo01;



import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.lang.reflect.Field;

/**
 * @author zhuzhizun
 * @date 2021/7/19
 */
@Getter
@Setter
public class Student {
    private String name;
    private Integer age;
    private String phone;

    public Student(String name, Integer age, String phone) {
        this.name = name;
        this.age = age;
        this.phone = phone;
    }

    public Student() {
    }

    @Override
    public String toString() {
        ToStringBuilder toStringBuilder = new ToStringBuilder(this);
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            try {
                toStringBuilder.append(field.getName(),field.get(this)).append("\n");
            } catch (IllegalAccessException e) {
                toStringBuilder.append("toString builder encounter an error");
            }
        }
        return  toStringBuilder.toString();
    }


    public static void main(String[] args) {
        Student student = new Student("zzz", 21, "13648380723");
        System.out.println(student.toString());
    }

}
